exports.MMControlLayer = GL2.Node.subclass(
{
    classname: 'MMControlLayer',
    
    initialize: function() 
    {
		this._topBar = null;
		this._bottomBar = null;
		this._actionAlert = null;
    },
	
	createView: function()
	{
		//add bottom bar
		this._bottomBar = new MMBottomBar();
		this._bottomBar.createView();
		this._bottomBar.setDepth(1);
		this.addChild(this._bottomBar);
		
		//add Top Bar		
		this._topBar = new MMTopBar();
		this._topBar.createView();
		this._topBar.setDepth(1);
		this.addChild(this._topBar)
		
		//Play back ground music
		this.playBackgroundMusicIfOn();
	},
	
	playBackgroundMusicIfOn: function()
	{
		var musicOn = MMSoundManager.getMusicState();
		if(musicOn == "true")
		{
			MMSoundManager.playBackgroundSound();
		}
	},
	
	showSocialInteractionUI: function()
	{
//		var leftArrow = this.getBaseResourcePath()+"arrow-left.png";
//		var rightArrow = this.getBaseResourcePath()+"arrow-right.png";
//		
//		this._rightButton = new GLButton(rightArrow, rightArrow, TCUtil.getAdjustedX(80),TCUtil.getAdjustedY(40), this.temporaryFUNC.bind(this), this, 1, "", null, null, null, null);
//		this._rightButton.setPosition(TCUtil.getAdjustedX(285),TCUtil.getAdjustedY(200));
//		
//		this._leftButton = new GLButton(leftArrow, leftArrow, TCUtil.getAdjustedX(80),TCUtil.getAdjustedY(40), this.temporaryFUNC.bind(this), this, 1, "", null, null, null, null);
//		this._leftButton.setPosition(TCUtil.getAdjustedX(35),TCUtil.getAdjustedY(200));
		this._socialUI = new ScrollGenericView();
	    this.addChild(this._socialUI);
	    
	    
		var addFriendNormal = this.getBaseResourcePath()+"add-friend-normal.png";
		var addFriendPressed = this.getBaseResourcePath()+"add-friend-pressed.png";
		
		this._friendFinder = new GLButton(addFriendNormal, addFriendPressed, TCUtil.getAdjustedX(60),TCUtil.getAdjustedY(60), this.showMobageUserFinder.bind(this), this, 3, Core.Localization.getString("ADD_FRIENDS"), new Core.Color(0,0,0), null, null, TCUtil.getAdjustedFontSize(90));
		this._friendFinder.setPosition(TCUtil.getAdjustedX(280),TCUtil.getAdjustedY(220));
		this._friendFinder.setDisabledImagePath(addFriendPressed);	    
		this._friendFinder.setButtonTextBelowButton();
	},
	
	showMobageUserFinder: function()
	{
		Social.Common.Service.openUserFinder();
	},
	
	removeSocialInteractionUI: function()
	{
//		if(this._rightButton)
//		{
//			this._rightButton.destroy();
//			this._rightButton = null;
//		}
//		if(this._leftButton)
//		{
//			this._leftButton.destroy();
//			this._leftButton = null;
//		}
		if(this._socialUI)
		{
			this._socialUI.destroy();
			this._socialUI = null;
		}
		if(this._friendFinder)
		{
			this._friendFinder.destroy();
			this._friendFinder = null;
		}
	},
	
	disableMobageUserFinder: function()
	{
		this._friendFinder.setIsEnabled(false);
	},
	
	enableMobageUserFinder: function()
	{
		this._friendFinder.setIsEnabled(true);
	},

	getBaseResourcePath: function()
	{
		return "./Content/images/gamelayer/controllayer/";
	},
	
	getBottomBar: function()
	{
		if(this._bottomBar) {
			return this._bottomBar;
		}
		return null;
	},
	
	getTopBar: function()
	{
		if(this._topBar) {
			return this._topBar;
		}
		return null;
	},
		
	getBottomBarHeight : function() {
		if(this._bottomBar) {
			return this._bottomBar.getNodeHeight();
		}
		return null;
	},
	
	getTopBarHeight : function() {
		if(this._topBar) {
			return this._topBar.getNodeHeight();
		}
		return null;
	},
	
	addActionAlertWindow: function(actionType)
	{
		if(this._actionAlert)
		{
			this._actionAlert.destroy();
			this._actionAlert = null;
		}
		//else
		//{
			this._actionAlert = new MMActionAlertWindow(actionType);
			this._actionAlert.createView();
			this.addChild(this._actionAlert);
		//} 
	},
	
	getActionAlertWindow: function()
	{
		if(this._actionAlert)
		{
			return this._actionAlert;		
		}			
		return null
	},
	
	removeActionAlertWindow: function()
	{
		if(this._actionAlert)
		{
			this._actionAlert.destroy();
			this._actionAlert = null;
		}
	},
	
	    
	destroy: function()
    {
    	this.removeSocialInteractionUI();
		if(this._topBar)
		{
			this._topBar.destroy();
			this._topBar = null;
		}
		if(this._bottomBar)
		{
			this._bottomBar.destroy();
			this._bottomBar = null;
		}
		if(this._actionAlert)
		{
			this._actionAlert.destroy();
			this._actionAlert = null;
		}
		if(this._friendFinder)
		{
			this._friendFinder.destroy();
			this._friendFinder = null;
		}
    },
});
